package com.zzr.demo.redis.controller;

import com.zzr.demo.redis.service.LikesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;
import java.util.UUID;

/**
 * @author: xiaomi
 * @date: 2021/10/8
 * @description:
 */
@RestController
@RequestMapping("likes/")
@Api(tags = "点赞：点赞、取消、统计")
@Slf4j
public class LikesController {


    @Autowired
    LikesService likesService;

    @GetMapping("/likes/{paperId}")
    @ApiOperation("点赞")
    public boolean likes(@PathVariable("paperId") String paperId) {
        //mock userId
        String userId = UUID.randomUUID().toString();
        likesService.likes(paperId, userId);
        return true;
    }

    @GetMapping("/unlike/{paperId}/{userId}")
    @ApiOperation("取消点赞")
    public boolean unlike(@PathVariable("paperId") String paperId, @PathVariable("userId") String userId) {
        likesService.unlike(paperId, userId);
        return true;
    }


    @GetMapping("/getAllUsers/{paperId}")
    @ApiOperation("获取所有点赞的人")
    public Set<String> getAllUsers(@PathVariable("paperId") String paperId) {
        Set<String> likesUsers = likesService.getLikesUsers(paperId);
        return likesUsers;
    }

    @GetMapping("/getCount/{paperId}")
    @ApiOperation("获取所有点赞的数量")
    public long getCount(@PathVariable("paperId") String paperId) {
        long size = likesService.getLikesCount(paperId);
        return size;
    }
}
